const BaseRest = require('./base.js');
/* 分销系统商户信息 */
module.exports = class extends BaseRest {
  /**
	 * 获取代理商的信息
	 * @return {[type]} [description]
	 */
  async getAction() {
    let data;
    const map = {};
    // 获取详情
    if (this.id) {
      map.id = this.id;
      data = await this.modelInstance.where(map).find();
      return this.success(data);
    }

    if (this.get('uid')) {
      map.uid = this.get('uid');
      data = await this.modelInstance.where(map).find();
      return this.success(data);
    }

    // 是否获取全部
    // 关键词
    const key = this.get('key');
    if (key) {
      map['merchant_name|telphone|linkman|address'] = ['like', '%' + key + '%'];
    }

    // 页码
    const page = this.get('page') || 1;
    // 每页显示数量
    const pageSize = this.get('pageSize') || 5;
    data = await this.modelInstance.where(map).page(page, pageSize).order('create_time desc').fieldReverse('update_time,create_time').countSelect();

    return this.success(data);
  }
};
